package com.idanchuang.component.dispatcher.action.exception.handler;

import com.idanchuang.component.base.exception.exception.BusinessException;
import com.idanchuang.component.logback.helper.LogContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class SimpleActionExceptionHandler implements ActionExceptionHandler {

    private static final Logger log = LoggerFactory.getLogger(SimpleActionExceptionHandler.class);

    @Override
    public void handle(Exception e, String module, String cmd, Object... params) {
        if (e instanceof BusinessException) {
            LogContext.setKeyword("ActionExceptionHandlerBusiness");
            log.warn("ActionExceptionHandler exception, message: {}", e.getMessage());
        } else {
            LogContext.setKeyword("ActionExceptionHandlerSystem");
            log.error("ActionExceptionHandler exception, request params: {}", params, e);
        }
    }
}
